<template>
<div class="distributor-vip views-container">
    <div class="wlm-table">
        <!-- <div class="wlm-table-hearder-btn"> -->
        <!-- <choose-goods ref="chooseGoods" :isShow="false" :config="chooseGoodsConfig" :changeEvt="chooseGoods"></choose-goods> -->
        <!-- </div> -->
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="85px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="会员卡名称：" class="search">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.name" placeholder="请输入商品名称" style="width:200px;"></el-input>
                    </el-form-item>
                    <el-form-item label="分销状态：" class="filter">
                        <el-select v-model="tableFormatData.userTable.files.dealer_status" placeholder="请选择">
                            <el-option v-for="item in [{lable:'全部',value:''},{lable:'参与分销',value:'1'},{lable:'不参与分销',value:'0'}]" :key="item.value" :label="item.lable" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="date" label="会员卡名称" >
                    <template slot-scope="scope">
                        <span>{{ scope.row.card_title}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="会员卡类型" >
                    <template slot-scope="scope">
                        <span>{{cardTypeMap[`${scope.row.card_type}`]}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="会员卡时长" >
                    <template slot-scope="scope" v-if="Array.isArray(scope.row.card_time_date)">
                        <span v-if="scope.row.card_time_date.length == 1">{{`${scope.row.card_time_date[0]}天`}}</span>
                        <span v-if="scope.row.card_time_date.length == 2">{{scope.row.card_time_date[0] | parseTime('{y}-{m}-{d}')}} - {{scope.row.card_time_date[1] | parseTime('{y}-{m}-{d}')}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="会员卡价格" >
                    <template slot-scope="scope">
                        <span class="text-danger">￥{{scope.row.card_price}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="会员卡状态" >
                    <template slot-scope="scope">
                        <span>{{cardStateMap[`${scope.row.card_state}`]}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="参与分销" >
                    <template slot-scope="scope">
                        <el-switch :active-value="1" :inactive-value="0" @change="changeTableItem({ids:[scope.row.card_id],status:scope.row.is_distribution},tableFormatData.userTable.change.is_distribution,{isWarning: scope.row.is_distribution === 1,warning:'是否参与分销？',cancel:{msg:'已取消',val:{scope:scope,cancelStatus:{key:'is_distribution',val:0}}}})" v-model="scope.row.is_distribution"> </el-switch>
                    </template>
                </el-table-column>
                <el-table-column min-width="100" prop="address" label="操作" >
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <router-link class="wlm-text" tag="span" :to="{path:'/distribution/distributorVipSetting', query:{card_id:scope.row.card_id}}">
                                <el-button type="text">设置佣金</el-button>
                            </router-link>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                </el-row>
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  memberDealer,
  getMemberCard
} from '@/api/application'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'DistributorVip',
  components: {

  },
  created() {
    this.$nextTick(() => {
    //   categoryIndex().then((response) => {
    //     const { data: { data: msgData = [] }} = response
    //     this.categoryData = msgData
    //   })
    })
  },
  computed: {
    stockAllNum() {
      return function(val) {
        let result = 0
        val.map(item => {
          result += item.stock_num
        })
        return result
      }
    }
  },
  data() {
    return {
      cardTypeMap: {
        '1': '时间卡',
        '2': '日期卡'
      },
      cardStateMap: {
        '1': '未开始',
        '2': '使用中',
        '3': '已过期'
      },
      myProps: {
        value: 'category_id',
        label: 'name',
        children: 'child'
      },
      category_array: [],
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getMemberCard
          },
          tableData: [],
          files: {
            name: '',
            category: '',
            card_is_sell: '1',
            // status: '',
            dealer_status: '',
            ids: [],
            checkall: '0',
            Recycle: '0'
          },
          change: {
            is_distribution: {
              key: 'is_distribution',
              api: memberDealer
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {

  }
}
</script>

<style lang="scss" scoped>
.distributor-vip {
    .logo {
        height: 32px;
        width: 32px;
        border-radius: 32px;
        vertical-align: middle;
    }
}
</style>
